#include  "ThreadPool.hpp"
#include "Task.hpp"
#include<unistd.h>
#include<chrono>
#include<thread>
#include<time.h>
void* pro(void* arg)
{
  ThreadPool<Task>* bq = static_cast<ThreadPool<Task>*>(arg);
  const char* str_op = "+-*/%";
  while(1)
  {
    std::this_thread::sleep_for(std::chrono::seconds(2));
    //usleep(1000000);
    int x = rand() % 10 + 1;
    int y = rand() % 11 + 1;
    char op = str_op[rand() %4];
    cout <<"生产者构造任务：" << x <<" " <<op  <<" " <<y <<"  = ?" <<endl; 
    Task task(x,y,op);
    bq->push(task);
  }
}


int main()
{
  ThreadPool<Task> rq;
  //pthread_t tid1,tid2; 
  //pthread_create(&tid1,nullptr,pro,(void*)&bq);
  //pthread_create(&tid2,nullptr,com,(void*)&bq);

  //pthread_join(tid1,nullptr);
  //pthread_join(tid2,nullptr);
  
  pthread_t p_tid[5];
  for(int i = 0;i<5;i++)
  {
    pthread_create(&p_tid[i],nullptr,pro,(void*)&rq);
  }
  for(int i = 0;i<5;i++)
  {
    pthread_join(p_tid[i],nullptr);
  }
  return 0;
}
